home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format CD 46
/
Amiga Format CD46 (1999-10-20)(Future Publishing)(GB)[!][issue 1999-12].iso
/
-in_the_mag-
/
synth_studies
/
resgrep03b
/
source
/
exportedit.cc
< prev
next >
Wrap
C/C++ Source or Header
|
1999-09-15
|
19KB
|
758 lines
//
// Editieren der Conversions-Liste
//
extern "C" {
#include <exec/types.h>
#include <intuition/intuition.h>
#include <intuition/classes.h>
#include <intuition/classusr.h>
#include <intuition/imageclass.h>
#include <intuition/gadgetclass.h>
#include <libraries/gadtools.h>
#include <graphics/displayinfo.h>
#include <graphics/gfxbase.h>
#include <dos/dos.h>
#include <stdlib.h>
};
#include "id.h"
#include "export.h"
#include "resgrep.h"
#include "utils.h"
extern "C" {
char *strdup(char *);
#include <clib/exec_protos.h>
#include <clib/gadtools_protos.h>
#include <clib/intuition_protos.h>
};
#define GD_convert 0
#define GD_to 1
#define GD_command 2
#define GD_cfind 3
#define GD_arexx 4
#define GD_writeto 5
#define GD_file 6
#define GD_ffind 7
#define GD_ok 8
#define GD_cancel 9
#define GD_add 10
#define GD_remove 11
struct Window *Wnd = 0l;
struct Gadget *GList = 0l;
struct Gadget *Gadgets[12];
extern list *conversions;
UBYTE **convertLabels;
UBYTE **toLabels;
char **makeConvertLabels(void)
{
int index=0;
char **b;
node *n;
unsigned long last=0;
// Voraussetzung: mindestens ZWEI Elemente in der Liste
last = conversions->getfirst()->getpack();
index++;
for(n=conversions->getfirst(); n->getsucc(); n=n->getsucc() )
if( last!=n->getpack() )
{
index++;
last=n->getpack();
}
if( (b=(char **)malloc(sizeof(*b)*(index+1)))==NULL )
return NULL;
index=0;
last = conversions->getfirst()->getpack();
b[index++]=strdup(pack2cstr(conversions->getfirst()->getpack()));
for(n=conversions->getfirst(); n->getsucc(); n=n->getsucc())
if( last!=n->getpack() )
{
b[index++]=strdup(pack2cstr(n->getpack()));
last=n->getpack();
}
b[index]=NULL;
return b;
}
char **makeToLabels(unsigned long p)
{
int index=0;
char **b;
for(node *n=conversions->findpack(p);
n!=NULL && n->getsucc() && n->getpack()==p;
n=n->getsucc(), index++)
;
if( (b=(char **)malloc(sizeof(*b)*(index+1)))==NULL )
return NULL;
for(index=0,n=conversions->findpack(p);
n!=NULL && n->getsucc() && n->getpack()==p;
n=n->getsucc(),index++)
b[index]=n->getname();
b[index]=NULL;
return b;
}
// Sucht aus dem 'ConvNum'ten Übertragungsart die 'ToNum'te aus.
node *getselnode(int ConvNum, int ToNum)
{
node *n;
unsigned long last;
if( ConvNum==0 )
n=conversions->getfirst();
else
{
last = conversions->getfirst()->getpack();
for(n=conversions->getfirst(); n->getsucc(); n=n->getsucc() )
if( last!=n->getpack() )
{
ConvNum--;
last=n->getpack();
if( ConvNum==0 )
break;
}
if( ConvNum!=0 )
return NULL; // Nicht gefunden
}
for(;n->getsucc() && ToNum>0; n=n->getsucc(), ToNum--)
;
return n;
}
void ActiveNode(node *n)
{
node *vor;
conversions->remove(n);
if( (vor=conversions->findpack(n->getpack()))==NULL )
conversions->enqueuepack(n);
else
conversions->insert(vor->getpred(),n);
}
// Liesst den Text aus dem File- und dem Command-Gadget
void convert::ReadText(void)
{
struct StringInfo *si;
struct Gadget *g;
if( command != NULL )
free(command);
command=NULL;
if( filename != NULL )
free(filename);
filename=NULL;
// g = Gadgets[GD_command];
// si = (struct StringInfo *)(g->SpecialInfo);
// command = strdup( (char *) si->Buffer );
command = strdup( (char *)
((struct StringInfo *)(Gadgets[GD_command]->SpecialInfo))->Buffer);
filename = strdup( (char *)
((struct StringInfo *)(Gadgets[GD_file]->SpecialInfo))->Buffer );
}
// Stellt den Inhalt des Knotens in dem Fenster dar.
void UpdateWindow(node *SelNode, int ConvNum)
{
convert *c=(convert *)SelNode;
GT_SetGadgetAttrs(Gadgets[GD_convert],Wnd,NULL,GTCY_Labels,convertLabels,
GTCY_Active,ConvNum, TAG_DONE );
if( toLabels!=NULL )
free(toLabels);
toLabels=(UBYTE **)makeToLabels(SelNode->getpack());
GT_SetGadgetAttrs(Gadgets[GD_to],Wnd,NULL,GTCY_Labels,toLabels,
TAG_DONE );
GT_SetGadgetAttrs(Gadgets[GD_command],Wnd,NULL,GTST_String,c->command,TAG_DONE);
GT_SetGadgetAttrs(Gadgets[GD_arexx],Wnd,NULL,GTCB_Checked,c->isARexx,TAG_DONE);
GT_SetGadgetAttrs(Gadgets[GD_file],Wnd,NULL,GTST_String,c->filename,TAG_DONE);
if( c->sendto==Clipboard )
{
GT_SetGadgetAttrs(Gadgets[GD_writeto],Wnd,NULL,GTCY_Active,0,TAG_DONE);
GT_SetGadgetAttrs(Gadgets[GD_file],Wnd,NULL,GA_Disabled,TRUE,TAG_DONE);
}
else
{
GT_SetGadgetAttrs(Gadgets[GD_writeto],Wnd,NULL,GTCY_Active,1,TAG_DONE);
GT_SetGadgetAttrs(Gadgets[GD_file],Wnd,NULL,GA_Disabled,FALSE,TAG_DONE);
}
}
// ------------------------------------------------------------------------
// Das Add Fenster
// Rückgabewerte:
// 0: Keinen Fehler
// 1: Konnte Kontext nicht anlegen
// 2: Konnte Gadget nicht anlegen
// 3: Fehler beim kreiren der Menus
// 4: Fehler beim öffnen des Fensters
// 11: Fehlerhafter Typ.
int addconv(unsigned long *newtype)
{
#define GDA_resourcetype 0
#define GDA_ok 1
#define GDA_cancel 2
struct Window *AWnd = NULL;
struct Gadget *AGList = NULL;
struct Menu *AMenus = NULL;
struct Gadget *AGadgets[3];
UWORD ALeft = 169;
UWORD ATop = 89;
UWORD AWidth = 261;
UWORD AHeight = 54;
UBYTE *AWdt = (UBYTE *)" Add Resource Type";
struct TextAttr topaz8 =
{
( STRPTR )"topaz.font", 8, 0x00, 0x41
};
struct NewMenu ANewMenu[] =
{
NM_TITLE, (UBYTE *)"Control", NULL, 0, 0, NULL,
NM_ITEM, (UBYTE *)"Ok", (UBYTE *)"O", 0, 0, NULL,
NM_ITEM, (UBYTE *)"Cancel", (UBYTE *)"C", 0, 0, NULL,
NM_ITEM, (UBYTE *)NM_BARLABEL, NULL, 0, NULL, NULL,
NM_ITEM, (UBYTE *)"Close Window", (UBYTE *)"K", 0, 0, NULL,
NM_END, NULL, NULL, 0, NULL, NULL
};
struct NewGadget ng;
struct Gadget *g;
UWORD offx, offy;
struct IntuiMessage theIMsg, *imsg;
char *newtypestring;
offx = theScreen->WBorLeft;
offy = theScreen->WBorTop + theScreen->RastPort.TxHeight + 1;
if ( NOT( g = CreateContext( &AGList )))
return( 1L );
ng.ng_LeftEdge = offx + 158;
ng.ng_TopEdge = offy + 6;
ng.ng_Width = 56;
ng.ng_Height = 13;
ng.ng_GadgetText = (UBYTE *)"Recource Type";
ng.ng_TextAttr = &topaz8;
ng.ng_GadgetID = GDA_resourcetype;
ng.ng_Flags = PLACETEXT_LEFT;
ng.ng_VisualInfo = VisualInfo;
g = CreateGadget( STRING_KIND, g, &ng, GTST_MaxChars, 4, TAG_DONE );
AGadgets[ 0 ] = g;
ng.ng_LeftEdge = offx + 26;
ng.ng_TopEdge = offy + 27;
ng.ng_Width = 77;
ng.ng_Height = 18;
ng.ng_GadgetText = (UBYTE *)"Ok";
ng.ng_GadgetID = GDA_ok;
ng.ng_Flags = PLACETEXT_IN;
g = CreateGadget( BUTTON_KIND, g, &ng, TAG_DONE );
AGadgets[ 1 ] = g;
ng.ng_LeftEdge = offx + 154;
ng.ng_TopEdge = offy + 26;
ng.ng_Width = 76;
ng.ng_GadgetText = (UBYTE *)"Cancel";
ng.ng_GadgetID = GDA_cancel;
g = CreateGadget( BUTTON_KIND, g, &ng, TAG_DONE );
AGadgets[ 2 ] = g;
if ( NOT g )
return( 2L );
if ( NOT( AMenus = CreateMenus( ANewMenu, GTMN_FrontPen, NULL, TAG_DONE )))
return( 3L );
LayoutMenus( AMenus, VisualInfo, GTMN_TextAttr, &topaz8, TAG_DONE );
if ( NOT( AWnd = OpenWindowTags( NULL,
WA_Left, ALeft,
WA_Top, ATop,
WA_Width, AWidth,
WA_Height, AHeight + offy,
WA_IDCMP, STRINGIDCMP | BUTTONIDCMP |
IDCMP_MENUPICK | IDCMP_REFRESHWINDOW,
WA_Flags, WFLG_DRAGBAR | WFLG_DEPTHGADGET |
WFLG_SMART_REFRESH | WFLG_ACTIVATE,
WA_Gadgets, AGList,
WA_Title, AWdt,
WA_ScreenTitle, "ResGrep - Add Resource Type",
TAG_DONE )))
return( 4L );
SetMenuStrip( AWnd, AMenus );
GT_RefreshWindow( AWnd, NULL );
for(;;) // Main Event Loop
{
Wait( 1UL<<(unsigned long)(AWnd->UserPort->mp_SigBit) );
while( (imsg=GT_GetIMsg(AWnd->UserPort)) != NULL )
{
// Message kopieren und orginale sofort zurückschicken.
theIMsg=*imsg;
GT_ReplyIMsg(imsg);
switch( theIMsg.Class )
{
case IDCMP_INTUITICKS:
break;
case IDCMP_MENUPICK:
{
int MenuNumber=theIMsg.Code;
struct MenuItem *Item;
while( MenuNumber!=MENUNULL )
{
Item=ItemAddress(Menus,MenuNumber);
switch( MENUNUM(MenuNumber) )
{
case 0:
switch( ITEMNUM(MenuNumber) )
{
case 0: // Ok
case 3: // Close Window
newtypestring = (char *)
((struct StringInfo *)(AGadgets[GDA_resourcetype]
->SpecialInfo))
->Buffer;
if ( AMenus )
{
ClearMenuStrip( AWnd );
FreeMenus( AMenus );
}
if ( AWnd )
CloseWindow( AWnd );
if ( AGList )
FreeGadgets( AGList );
if( strlen(newtypestring)!=4 )
return 11;
*newtype=cstr2pack(newtypestring);
return 0;
break;
case 1:
return 12;
if ( AMenus )
{
ClearMenuStrip( AWnd );
FreeMenus( AMenus );
}
if ( AWnd )
CloseWindow( AWnd );
if ( AGList )
FreeGadgets( AGList );
break;
default:
ResError("Fatal:\nUnknown Menuitem.");
break;
}
default:
ResError("Fatal:\nUnknown Menu.");
break;
}
MenuNumber=Item->NextSelect;
}
}
break;
case IDCMP_GADGETUP:
switch( ((struct Gadget *)theIMsg.IAddress)->GadgetID )
{
case GDA_ok:
newtypestring = (char *)
((struct StringInfo *)(AGadgets[GDA_resourcetype]
->SpecialInfo))
->Buffer;
if ( AMenus )
{
ClearMenuStrip( AWnd );
FreeMenus( AMenus );
}
if ( AWnd )
CloseWindow( AWnd );
if ( AGList )
FreeGadgets( AGList );
if( strlen(newtypestring)!=4 )
return 11;
*newtype=cstr2pack(newtypestring);
return 0;
case GDA_cancel:
if ( AMenus )
{
ClearMenuStrip( AWnd );
FreeMenus( AMenus );
}
if ( AWnd )
CloseWindow( AWnd );
if ( AGList )
FreeGadgets( AGList );
return 12;
break;
case GDA_resourcetype:
break;
default:
ResError("Fatal:\nUnknown Gadget");
break;
}
break;
default:
ResError("Fatal:\nUnknown Message.");
break;
}
}
} // Forever
return 13;
}
// ------------------------------------------------------------------------
// Das Editfenster.
void editconv(void)
{
int ConvNum=0, ToNum=0, WriteDataNum=0;
node *SelectedNode;
UBYTE *writetoLabels[] =
{
(UBYTE *)"Clipboard", (UBYTE *)"File", 0l
};
struct TextAttr topaz8 = {
( STRPTR )"topaz.font", 8, 0x00, 0x01 };
struct TagItem WindowTags[] =
{
WA_Left, 112,
WA_Top, 56,
WA_Width, 388,
WA_Height, 144,
WA_IDCMP, IDCMP_GADGETUP | IDCMP_CLOSEWINDOW |
IDCMP_REFRESHWINDOW,
WA_Flags, WFLG_DRAGBAR | WFLG_DEPTHGADGET |
WFLG_CLOSEGADGET | WFLG_SMART_REFRESH |
WFLG_ACTIVATE,
WA_Gadgets, 0l,
WA_Title, (ULONG)"Edit Conversions",
WA_ScreenTitle, (ULONG)"ResGrep - Edit Conversions",
WA_MinWidth, 67,
WA_MinHeight, 21,
WA_MaxWidth, 640,
WA_MaxHeight, 256,
TAG_DONE
};
struct NewGadget ng;
struct Gadget *g;
struct IntuiMessage theIMsg, *imsg;
convertLabels=(UBYTE **)makeConvertLabels();
toLabels=(UBYTE **)makeToLabels( cstr2pack((char *)*convertLabels) );
if ( NOT( g = CreateContext( &GList )))
return;
ng.ng_LeftEdge = 80;
ng.ng_TopEdge = 19;
ng.ng_Width = 81;
ng.ng_Height = 13;
ng.ng_GadgetText = (UBYTE *)"Convert";
ng.ng_TextAttr = &topaz8;
ng.ng_GadgetID = GD_convert;
ng.ng_Flags = PLACETEXT_LEFT;
ng.ng_VisualInfo = VisualInfo;
g = CreateGadget(CYCLE_KIND,g, &ng, GTCY_Labels, convertLabels, TAG_DONE );
Gadgets[ 0 ] = g;
ng.ng_LeftEdge = 207;
ng.ng_Width = 155;
ng.ng_GadgetText = (UBYTE *)"to";
ng.ng_GadgetID = GD_to;
g = CreateGadget( CYCLE_KIND, g, &ng, GTCY_Labels, toLabels, TAG_DONE );
Gadgets[ 1 ] = g;
ng.ng_LeftEdge = 80;
ng.ng_TopEdge = 39;
ng.ng_Width = 201;
ng.ng_GadgetText = (UBYTE *)"Command";
ng.ng_GadgetID = GD_command;
g = CreateGadget( STRING_KIND, g, &ng, GTST_MaxChars, 256, TAG_DONE );
Gadgets[ 2 ] = g;
ng.ng_LeftEdge = 292;
ng.ng_Width = 70;
ng.ng_GadgetText = (UBYTE *)"Find...";
ng.ng_GadgetID = GD_cfind;
ng.ng_Flags = PLACETEXT_IN;
g = CreateGadget( BUTTON_KIND, g, &ng, GA_Disabled, TRUE, TAG_DONE );
Gadgets[ 3 ] = g;
ng.ng_LeftEdge = 81;
ng.ng_TopEdge = 61;
ng.ng_GadgetText = (UBYTE *)"ARexx";
ng.ng_GadgetID = GD_arexx;
ng.ng_Flags = PLACETEXT_LEFT;
g = CreateGadget( CHECKBOX_KIND, g, &ng, GTCB_Checked, TRUE, TAG_DONE );
Gadgets[ 4 ] = g;
ng.ng_LeftEdge = 233;
ng.ng_TopEdge = 60;
ng.ng_Width = 128;
ng.ng_Height = 13;
ng.ng_GadgetText = (UBYTE *)"Write Data to";
ng.ng_GadgetID = GD_writeto;
g = CreateGadget(CYCLE_KIND,g, &ng, GTCY_Labels, writetoLabels, TAG_DONE );
Gadgets[ 5 ] = g;
ng.ng_LeftEdge = 80;
ng.ng_TopEdge = 83;
ng.ng_Width = 201;
ng.ng_GadgetText = (UBYTE *)"File";
ng.ng_GadgetID = GD_file;
g = CreateGadget( STRING_KIND, g, &ng, GTST_MaxChars, 256, TAG_DONE );
Gadgets[ 6 ] = g;
ng.ng_LeftEdge = 292;
ng.ng_Width = 70;
ng.ng_GadgetText = (UBYTE *)"Find...";
ng.ng_GadgetID = GD_ffind;
ng.ng_Flags = PLACETEXT_IN;
g = CreateGadget( BUTTON_KIND, g, &ng, GA_Disabled, TRUE, TAG_DONE );
Gadgets[ 7 ] = g;
ng.ng_LeftEdge = 13;
ng.ng_TopEdge = 110;
ng.ng_Width = 86;
ng.ng_Height = 19;
ng.ng_GadgetText = (UBYTE *)"OK";
ng.ng_GadgetID = GD_ok;
g = CreateGadget( BUTTON_KIND, g, &ng, TAG_DONE );
Gadgets[ 8 ] = g;
ng.ng_LeftEdge = 291;
ng.ng_GadgetText = (UBYTE *)"Cancel";
ng.ng_GadgetID = GD_cancel;
g = CreateGadget( BUTTON_KIND, g, &ng, GA_Disabled, TRUE, TAG_DONE );
Gadgets[ 9 ] = g;
ng.ng_LeftEdge = 106;
ng.ng_GadgetText = (UBYTE *)"Add...";
ng.ng_GadgetID = GD_add;
g = CreateGadget( BUTTON_KIND, g, &ng, TAG_DONE );
Gadgets[ 10 ] = g;
ng.ng_LeftEdge = 198;
ng.ng_GadgetText = (UBYTE *)"Remove";
ng.ng_GadgetID = GD_remove;
g = CreateGadget( BUTTON_KIND, g, &ng, TAG_DONE );
Gadgets[ 11 ] = g;
if ( NOT g )
return;
WindowTags[ 6 ].ti_Data = (ULONG)GList;
if ( NOT( Wnd = OpenWindowTagList( 0l, WindowTags )))
return;
GT_RefreshWindow( Wnd, 0l );
SelectedNode = getselnode(ConvNum,ToNum); // Initialisieren
UpdateWindow(SelectedNode,ConvNum);
for(;;) // Main Event Loop
{
Wait( 1UL<<(unsigned long)(Wnd->UserPort->mp_SigBit) );
while( (imsg=GT_GetIMsg(Wnd->UserPort)) != NULL )
{
// Message kopieren und orginale sofort zurückschicken.
theIMsg=*imsg;
GT_ReplyIMsg(imsg);
switch( theIMsg.Class )
{
case IDCMP_INTUITICKS:
break;
case IDCMP_CLOSEWINDOW:
((convert *)SelectedNode)->ReadText();
ActiveNode(SelectedNode);
if( Wnd )
CloseWindow( Wnd );
if ( GList )
FreeGadgets( GList );
return;
break;
case IDCMP_GADGETUP:
switch( ((struct Gadget *)theIMsg.IAddress)->GadgetID )
{
case GD_convert:
((convert *)SelectedNode)->ReadText();
ActiveNode(SelectedNode);
ConvNum = theIMsg.Code;
ToNum = 0;
SelectedNode = getselnode(ConvNum,ToNum);
if( SelectedNode!=NULL )
UpdateWindow(SelectedNode,ConvNum);
break;
case GD_to:
((convert *)SelectedNode)->ReadText();
ToNum = theIMsg.Code;
SelectedNode = getselnode(ConvNum,ToNum);
if( SelectedNode!=NULL )
UpdateWindow(SelectedNode,ConvNum);
break;
case GD_command: // Wird schon in 'convert' und 'to' erledigt.
case GD_file:
break;
case GD_arexx:
((convert *)SelectedNode)->isARexx =
((convert *)SelectedNode)->isARexx ? false : true ;
break;
case GD_writeto:
switch( theIMsg.Code )
{
case 0:
((convert *)SelectedNode)->sendto = Clipboard;
break;
case 1:
((convert *)SelectedNode)->sendto = File;
break;
default:
ResError("Fatal:\nUnknown WriteTo method.");
break;
}
if( SelectedNode!=NULL )
UpdateWindow(SelectedNode,ConvNum);
break;
case GD_ok:
((convert *)SelectedNode)->ReadText();
ActiveNode(SelectedNode);
if( Wnd )
CloseWindow( Wnd );
if ( GList )
FreeGadgets( GList );
ActiveNode(SelectedNode);
return;
break;
case GD_add:
{
unsigned long newtype, ret;
if( (ret=addconv(&newtype))!=0 )
{
if( ret!= 12)
ResError("An Error occured while\n"
"adding a new conversion.");
break;
}
conversions->enqueuepack( new
convert(newtype,0,"raw data",NULL,
false,File,"T:ResGrepRawData",false) );
if(convertLabels!=NULL)
free(convertLabels);
convertLabels=(UBYTE **)makeConvertLabels();
ConvNum=0;
ToNum=0;
SelectedNode = getselnode(ConvNum,ToNum); // Initialisieren
UpdateWindow(SelectedNode, ConvNum);
}
break;
case GD_remove:
if( ((convert *)SelectedNode)->builtin==true )
{
ResError("Can't remove builtin function.");
break;
}
conversions->remove(SelectedNode);
if(convertLabels!=NULL)
free(convertLabels);
convertLabels=(UBYTE **)makeConvertLabels();
ConvNum = 0;
ToNum = 0;
SelectedNode = getselnode(ConvNum,ToNum);
if( SelectedNode!=NULL )
UpdateWindow(SelectedNode,ConvNum);
break;
default:
ResError("Fatal:\nUnknown Gadget.\n");
break;
}
if( SelectedNode==NULL )
{
ResError("Fatal:\nSelected Node == NULL.\nBetter I quit.");
if( Wnd )
CloseWindow( Wnd );
if ( GList )
FreeGadgets( GList );
return;
}
break;
default:
printf("Unbekannte Meldg: %08lx %04x\n",theIMsg.Class, theIMsg.Code);
ResWarning("Unknown Message.\n");
}
}
} // End forever
}